package com.onion.utils.surface.response;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

public class Result implements java.io.Serializable{

    private static final long serialVersionUID = -6185283774075377752L;

    private static String CODE_KEY = "code";
    private static String MESSAGE_KEY = "message";

    protected int code;
    protected String message = "";
    protected Map<String,Object> dto = new HashMap<String,Object>();

    public Result(){}

    public static Result instance(int code, String message){
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static void initKey(String codeKey, String messageKey){
        if(StringUtils.isNotBlank(codeKey)){
            Result.CODE_KEY = codeKey;
        }
        if(StringUtils.isNotBlank(messageKey)){
            Result.MESSAGE_KEY = messageKey;
        }
    }

    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }

    public void put(String param, Object value){
        dto.put(param, value);
    }

    public Map<String,Object> returnMsg(){
        dto.put(StringUtils.isBlank(CODE_KEY) ? "code" : CODE_KEY, code);
        dto.put(StringUtils.isBlank(MESSAGE_KEY) ? "message" : MESSAGE_KEY, message);
        return dto;
    }

}